/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_driving_record.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.tb_driving_record.dao.TbDrivingRecordDao;
import com.thinkgem.jeesite.modules.tb_driving_record.entity.TbDrivingRecord;
import com.thinkgem.jeesite.modules.tb_waybill.dao.TbWaybillDao;
import com.thinkgem.jeesite.modules.tb_waybill.entity.TbWaybill;

/**
 * 车辆运输记录Service
 * @author ZhangYangZe
 * @version 2017-06-09
 */
@Service
@Transactional(readOnly = true)
public class TbDrivingRecordService extends CrudService<TbDrivingRecordDao, TbDrivingRecord> {

	@Autowired
	private TbWaybillDao tbWaybillDao;
	
	public TbDrivingRecord get(String id) {
		return super.get(id);
	}
	
	public List<TbDrivingRecord> findList(TbDrivingRecord tbDrivingRecord) {
		return super.findList(tbDrivingRecord);
	}
	
	public Page<TbDrivingRecord> findPage(Page<TbDrivingRecord> page, TbDrivingRecord tbDrivingRecord) {
		return super.findPage(page, tbDrivingRecord);
	}
	
	@Transactional(readOnly = false)
	public void save(TbDrivingRecord tbDrivingRecord) {
		TbWaybill tbWaybill = new TbWaybill();
		String state = tbDrivingRecord.getState();
		if("0".equals(state)){
			tbWaybill.setState("3");
		}else if("3".equals(state)){
			tbWaybill.setState("4");
		}
		tbWaybill.setId(tbDrivingRecord.getWaybill());
		tbWaybillDao.updateNew(tbWaybill);
		super.save(tbDrivingRecord);
	}
	
	@Transactional(readOnly = false)
	public void delete(TbDrivingRecord tbDrivingRecord) {
		super.delete(tbDrivingRecord);
	}
	
}